# models/base_model.py
from datetime import datetime, timezone
from typing import Optional

from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import Integer, String, DateTime

from app.core import DeclarativeBase


class DevicesStatus(DeclarativeBase):
    """"""
    __tablename__ = 'devices_status'
    
    id: Mapped[int] = mapped_column(Integer, primary_key=True)  # 设备id号
    location: Mapped[str] = mapped_column(String(50), nullable=False)  # 设备坐标，格式："x,y" <-> "层,列"
    status:Mapped[Optional[str]] = mapped_column(String(20), nullable=True)  # 设备状态
    action: Mapped[Optional[str]] = mapped_column(String(20), nullable=True)  # 当前动作
    update_time: Mapped[datetime] = mapped_column(
        DateTime(timezone=True),
        default=lambda: datetime.now(timezone.utc),
        onupdate=lambda: datetime.now(timezone.utc)
    )  # 更新时间，使用UTC时间
    
    def __repr__(self):
        return f"<DevicesStatus(id={self.id}, location={self.location}, status={self.status}, action={self.action}, update_time={self.update_time})>"